<template>
    <!-- 通用搜索 -->
    <transition name="el-zoom-in-bottom" mode="out-in">
        <div class="table-com-search" v-show="baTable.table.showComSearch">
            <slot name="tableHeaderSearch"></slot>
        </div>
    </transition>

    <!-- 操作按钮组 -->
    <div v-bind="$attrs" class="table-header ba-scroll-style">
        <template v-if="baTable.table.tableButtons">
            <template v-for="(item, idx) in baTable.table.tableButtons" :key="idx">
                <el-tooltip :content="item.tipName" placement="top">
                    <el-button v-blur @click="item.onClick" class="table-header-operate" type="primary">
                        <Icon :name="item.iconName" />
                        <span class="table-header-operate-text">{{ item.name }}</span>
                    </el-button>
                </el-tooltip>
            </template>
        </template>


        <!-- 右侧搜索框和工具按钮 -->
        <div class="table-search">
            <el-input class="xs-hidden quick-search" clearable />
            <div class="table-search-button-group">

                <el-dropdown :max-height="380" :hide-on-click="false">
                    <el-button
                        class="table-search-button-item right-border"
                        color="#dcdfe6"
                        plain
                        v-blur
                    >
                        <Icon size="14" name="el-icon-Grid" />
                    </el-button>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item v-for="(item, idx) in columnDisplay" :key="idx">
                                <el-checkbox
                                    v-if="item.prop"
                                    @change="onChangeShowColumn($event, item.prop)"
                                    :checked="!item.show"
                                    :model-value="item.show"
                                    size="small"
                                    :label="item.label"
                                />
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>

                <el-tooltip content="查询" placement="top">
                    <el-button class="table-search-button-item"  @click="baTable.table.showComSearch = !baTable.table.showComSearch" color="#dcdfe6" plain v-blur>
                        <Icon size="14" name="el-icon-Search" />
                    </el-button>
                </el-tooltip>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { computed,ref ,inject} from 'vue'
import type baTableClass from '/@/utils/baTableNew'
debugger
const baTable = inject('tableData') as baTableClass
const columnDisplay = computed(() => {
    let columnDisplayArr = []
    for (let item of baTable.table.column!) {
        item.enableColumnDisplayControl === false ? '' :  columnDisplayArr.push(item)
    }
    return columnDisplayArr
})

const onChangeShowColumn = (value: string | number | boolean, field: string) => {
    baTable.onTableHeaderAction('change-show-column', { field: field, value: value })
}
</script>


<style scoped lang="scss">
.table-header {
    position: relative;
    overflow-x: auto;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 100%;
    background-color: var(--ba-bg-color-overlay);
    border: 1px solid var(--ba-border-color);
    border-bottom: none;
    padding: 13px 15px;
    font-size: 14px;
    .table-header-operate-text {
        margin-left: 6px;
    }
}

.mlr-12 {
    margin-left: 12px;
}
.mlr-12 + .el-button {
    margin-left: 12px;
}
.table-search {
    display: flex;
    margin-left: auto;
    .quick-search {
        width: auto;
    }
}
.table-search-button-group {
    display: flex;
    margin-left: 12px;
    border: 1px solid var(--el-border-color);
    border-radius: var(--el-border-radius-base);
    overflow: hidden;
    button:focus,
    button:active {
        background-color: var(--ba-bg-color-overlay);
    }
    button:hover {
        background-color: var(--el-color-info-light-7);
    }
    .table-search-button-item {
        height: 30px;
        border: none;
        border-radius: 0;
    }
    .el-button + .el-button {
        margin: 0;
    }
    .right-border {
        border-right: 1px solid var(--el-border-color);
    }
}

html.dark {
    .table-search-button-group {
        button:focus,
        button:active {
            background-color: var(--el-color-info-dark-2);
        }
        button:hover {
            background-color: var(--el-color-info-light-7);
        }
        button {
            background-color: var(--ba-bg-color-overlay);
            el-icon {
                color: white !important;
            }
        }
    }
}
.table-com-search {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    background-color: var(--ba-bg-color-overlay);
    border: 1px solid var(--ba-border-color);
    border-bottom: none;
    padding: 13px 15px;
    font-size: 14px;
}
</style>
